package cate.game.farm.local.forbidden;

import cate.game.db.facade.KvLoader;
import cate.game.db.mongo.kv.KvMongo;
import cate.game.framework.ModuleMan;
import cate.game.util.IntervalCounter;
import easy.java.dev.note.NoteField;


public class ForbiddenManager extends ModuleMan {

    @NoteField(value = "种族禁地系统状态")
    public ForbiddenSPO status;

    public ForbiddenManager() {
    }

    @Override
    public void initDependent() {
        this.status = new KvLoader<>(game, ForbiddenSPO.class, KvMongo.KEY_FARM_FORBIDDEN).getBySrvId();
        this.status.initialize(game);
    }

    private IntervalCounter saveTrigger = new IntervalCounter(211);

    protected void tickSelf() {
        if (saveTrigger.trigger()) {
            save();
        }
    }

    public void handleReward(){
        status.handleReward();
    }

    @Override
    public void onWeekSpan() {
        super.onWeekSpan();
        handleReward();
        status.onWeekSpan();
    }

    @Override
    public void onDaySpan() {
        super.onDaySpan();
        status.onDaySpan();
    }

    private void save() {
        game.db.kv.save(status);
    }

    public void tick() {
        tickSelf();
    }

    @Override
    public void shutdown(){
        game.db.kv.save(status);
    }
}
